package com.tbit.config.rpc;

import com.tbit.common.utils.RpcSecurityUtil;
import com.tbit.maintain.api.AddFaultApi;
import com.tbit.maintain.api.MachineApi;
import com.tbit.maintain.api.StockMachineApi;
import feign.RequestInterceptor;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static com.tbit.common.constant.RpcConstants.RPC_HEADER_SECRET;
import static com.tbit.common.constant.RpcConstants.RPC_HEADER_TIME;

/**
 * rpc配置类
 *
 * @author <a href="mailto:chen.wutian@tbit.com.cn">BUGTian</a>
 * @since 2024/9/14
 */
@Configuration
@EnableFeignClients(clients = {StockMachineApi.class, AddFaultApi.class, MachineApi.class
                    })
public class RpcConfiguration {
    @Bean
    public RequestInterceptor requestInterceptor() {
        return requestTemplate -> {
            long t = System.currentTimeMillis();
            requestTemplate
                    .header(RPC_HEADER_SECRET, RpcSecurityUtil.encryption(t))
                    .header(RPC_HEADER_TIME, String.valueOf(t));
        };
    }

}
